﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 弹出框加载
        private void Form1_Load(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = getUserList();
        }
        public List<User> getUserList()
        {
            // 制造数据
            List<User> userList = new List<User>();
            String[] nameArr = { "张三","李四","王五"};
            for (int i = 0; i < 3; i++)
            {
                User one = new User();
                one.index = i;
                one.name = nameArr[i];
                one.sex = i % 2 == 0 ? "男" : "女";
                userList.Add(one);
            }
            return userList;
        }

        public class User
        {
            public int index { get; set; }
            public string name { get; set; }
            public string sex { get; set; }

        }
        // 打印数组
        public static void printArray(string [] arr)
        {
            foreach(var x in arr)
            {
                Console.WriteLine(x+"");
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;
            // MessageBox.Show(rowIndex + "");
            DataGridViewRow theRow = dataGridView1.Rows[rowIndex];
            int cellCount = theRow.Cells.Count;
            Console.WriteLine("行数据："+ theRow + theRow.Cells.Count);
            String [] cValue= {"","","",""};
            for(int i=0;i< cellCount; i++)
            {
                String str = theRow.Cells[i].Value.ToString();
                // Console.WriteLine(i + str);
                cValue[i] = str;
            }
            // printArray(cValue);
            Console.WriteLine("获得的数据："+cValue.GetValue(2));
        }

       
    }
}
